package apiTest;

import java.io.IOException;
import java.util.Date;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import beans.Person;

public class JsonTest {
	public static void main(String[] args) {
		byte[] json = null;
		ObjectMapper mapper = new ObjectMapper(); // create once, reuse

		Person p = new Person("yht", "25");

		try {
			json = mapper.writeValueAsBytes(p);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (int i = 0; i < json.length; i++) {
			System.out.println(json[i]);
		}

		XContentBuilder builder = null;

		try {
			builder = XContentFactory.jsonBuilder().startObject().value(json)

					.endObject();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			String json1 = builder.string();
			System.out.println(json1);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
